<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bdd.php';
require_once '../inc/fonctions_sql.php';

$message_action = "";

$action = isset($_POST["action"]) ? $action = $_POST["action"] : "";

if(isset($_GET["id"])) {
    $id = $_GET["id"];
}
else if(isset($_POST["id"])) {
    $id = $_POST["id"];
}
else {
    $id = "";
}

if($action==1) {
    //RECUPERATION DES VALEURS DU FORMULAIRE AUTOMATISEE
    $tab_name_form = array(
        "raison_sociale",
        "adresse",
        "telephone",
        "fax",
        "email",
        "observations"
    );
    
    $message_action = modifier_donnees("entreprises", $id, $tab_name_form);
}

$sql = "SELECT * FROM entreprises WHERE id=".$id;
$envoi_requete = mysqli_query($connexion_serveur, $sql);
$data = mysqli_fetch_array($envoi_requete);

?>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php require_once "../inc/css_bootstrap.php"; ?>
        
        <h1>Ajouter une Entreprise</h1>
            
            <?php if(!empty($message_action)) { ?>
                <div id="message_action" class="alert <?php echo $message_action["css_class"]; ?>"><?php echo $message_action["texte"]; ?></div>
            <?php } ?>
        
        
        <form name="form_ajouter" id="form_ajouter" method="post">
            <table class="table table-bordered">
                    <tr>
                        
                        <th>
                            Raison Sociale : 
                        </th>
                        <td>
                            <input type="text" name="raison_sociale" id="raison_sociale" class="form-control" required value="<?php echo $data["raison_sociale"]; ?>">
                        </td>
                        
                    </tr>

                    <tr>

                        <th>
                            Adresse : 
                        </th>
                        <td>
                            <textarea name="adresse" id="adresse" class="form-control champ_textarea"><?php echo $data["adresse"]; ?></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Telephone : 
                        </th>
                        <td>
                           <input type="tel" name="telephone" id="telephone" class="form-control" value="<?php echo $data["telephone"]; ?>">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Fax : 
                        </th>
                        <td>
                           <input type="tel" name="fax" id="fax" class="form-control" value="<?php echo $data["fax"]; ?>">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Email : 
                        </th>
                        <td>
                           <input type="email" name="email" id="email" class="form-control" value="<?php echo $data["email"]; ?>">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Observations : 
                        </th>
                        <td>
                            <textarea name="observations" id="observations" class="form-control champ_textarea"><?php echo $data["observations"]; ?></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <button type="submit" name="action" class="btn btn-warning" value="1"><span class="glyphicon glyphicon-ok"></span> Modifier</button>
                        </td>
                    </tr>
                </table>
        </form>
    </body>
</html>
